package com.bdqn.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.base.R;
import com.bdqn.base.logger.WebLogger;
import com.bdqn.pojo.ShopFeedback;
import com.bdqn.service.ShopFeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 反馈
 *
 * @author lilibo
 * @date 2021/10/09
 */
@Api(tags="反馈接口")
@RestController
@RequestMapping("/shopfeedback")
public class ShopFeedbackController {

    @Autowired
    private ShopFeedbackService shopFeedbackService;

    /**
     * 新增反馈记录
     *
     * @param shopFeedback
     * @return R
     */
    @ApiOperation("新增反馈记录")
    @WebLogger("新增反馈记录")
    @PostMapping("/add")
    public R save(@ApiParam("反馈对象") @RequestBody ShopFeedback shopFeedback) {
        return new R<>(shopFeedbackService.save(shopFeedback));
    }

    /**
     * 修改反馈记录
     *
     * @param shopFeedback
     * @return R
     */
    @ApiOperation("修改反馈记录")
    @WebLogger("修改反馈记录")
    @PostMapping("/update")
    public R update(@ApiParam("反馈对象") @RequestBody ShopFeedback shopFeedback) {
        return new R<>(shopFeedbackService.updateById(shopFeedback));
    }

    /**
     * 通过id删除一条反馈记录
     *
     * @param id
     * @return R
     */
    @ApiOperation("通过id删除一条反馈记录")
    @WebLogger("通过id删除一条反馈记录")
    @PostMapping("/delete")
    public R removeById(@ApiParam("反馈id") Integer id) {
        return new R<>(shopFeedbackService.removeById(id));
    }

    /**
     * 通过id查询单条反馈记录
     *
     * @param id
     * @return R
     */
    @ApiOperation("通过id查询单条反馈记录")
    @WebLogger("通过id查询单条反馈记录")
    @GetMapping("/{id}")
    public R<ShopFeedback> getById(@ApiParam("反馈id") @PathVariable Integer id) {
        return new R<>(shopFeedbackService.getById(id));
    }

    /**
     * 通过反馈信息查询反馈记录
     *
     * @param shopFeedback 反馈信息对象
     * @return R
     */
    @ApiOperation("通过反馈信息查询反馈记录")
    @WebLogger("通过反馈信息查询反馈记录")
    @GetMapping("/list")
    public R<List<ShopFeedback>> getList(@ApiParam("查询的反馈对象") ShopFeedback shopFeedback) {
        return new R<>(shopFeedbackService.getList(shopFeedback));
    }

    /**
     * 分页查询反馈
     *
     * @param pageNo 当前页
     * @param pageSize 每页条数
     * @param shopFeedback 反馈
     * @return
     */
    @ApiOperation("分页查询反馈")
    @WebLogger("分页查询反馈")
    @GetMapping("/page")
    public R<IPage<ShopFeedback>> getPage(@ApiParam("当前页") @RequestParam(required = false, defaultValue = "1")  Long pageNo, @ApiParam("每页条数") @RequestParam(required = false, defaultValue = "10") Long pageSize, @ApiParam("查询的反馈对象") ShopFeedback shopFeedback) {
        return new R<>(shopFeedbackService.getPage(new Page<>(pageNo, pageSize), shopFeedback));
    }

    /**
     * 分页查询反馈数据
     *
     * @param pageNo 当前页
     * @param pageSize 每页条数
     * @param shopFeedback 反馈
     * @return 返回对象中的count为数据总量
     */
    @ApiOperation("分页查询反馈数据")
    @WebLogger("分页查询反馈数据")
    @GetMapping("/pagelist")
    public R<List<ShopFeedback>> getPageList(@ApiParam("当前页") @RequestParam(required = false, defaultValue = "1")  Long pageNo, @ApiParam("每页条数") @RequestParam(required = false, defaultValue = "10") Long pageSize, @ApiParam("查询的反馈对象") ShopFeedback shopFeedback) {
        IPage<ShopFeedback> page = shopFeedbackService.getPage(new Page<>(pageNo, pageSize), shopFeedback);
        return new R<>(page.getRecords(), page.getTotal());
    }

}
